#ifndef __JIENING_MATRIX_HEAD__
#define __JIENING_MATRIX_HEAD__

#include <iostream>

class jieningMatrix
{
public:
	static const double ZEROVAL = 1.0e-9;
	jieningMatrix(unsigned int xlen, unsigned int ylen, double initvalues[]);
	jieningMatrix(unsigned int xlen=1, unsigned int ylen=1, double initvalue=0.0);
	//拷贝构造函数
	jieningMatrix(const jieningMatrix& obj);
	//赋值符重载
	jieningMatrix& operator =(const jieningMatrix& obj);

	//加号重载
	jieningMatrix operator +(const jieningMatrix& obj);
	jieningMatrix operator +(double val);
	jieningMatrix& operator +=(const jieningMatrix& obj);
	jieningMatrix& operator +=(double val);

	//减号重载
	jieningMatrix operator -(const jieningMatrix& obj);
	jieningMatrix operator -(double val);
	jieningMatrix& operator -=(const jieningMatrix& obj);
	jieningMatrix& operator -=(double val);

	//乘号重载
	jieningMatrix operator *(const jieningMatrix& obj);
	jieningMatrix operator *(double val);
	jieningMatrix& operator *=(const jieningMatrix& obj);
	jieningMatrix& operator *=(double val);

	double getValue(unsigned int xpos, unsigned int ypos);
	unsigned int getXlen();
	unsigned int getYlen();
	bool getMData(double* cptoptr, unsigned int cpsize);

	//交换r1行和r2行
	bool swapRow(unsigned int r1, unsigned int r2);
	//交换line1列和line2列
	bool swapLine(unsigned int line1, unsigned int line2);
	
	//去掉第y（0 base）行第x（0 base）列后子矩阵
	// 如果 xdrop = -1表示返回去掉第y（0 base）行后的子矩阵
	// 如果 ydrop = -1表示返回去掉第x（0 base）列后的子矩阵
	jieningMatrix getSubMatrix(int xdrop, int ydrop);

	// 高斯消元法，解线性方程组
	jieningMatrix computeFCZ();

	std::string toString() const;
	void doPrint() const;


	~jieningMatrix();

protected:
	unsigned int m_xlen;
	unsigned int m_ylen;
	double* m_values;
};

class jieningSquareMatrix : public  jieningMatrix
{
public:
	jieningSquareMatrix(unsigned int len, double initvalues[]);
	jieningSquareMatrix(unsigned int len=1, double initvalue=1.0);
	~jieningSquareMatrix();
	//拷贝构造函数
	jieningSquareMatrix(const jieningSquareMatrix& obj);
	jieningSquareMatrix(const jieningMatrix& obj);

	double doDetComputR();
	double doDetComput();
};

std::ostream& operator<<(std::ostream& out, jieningMatrix& mobj);
std::ostream& operator<<(std::ostream& out, const jieningMatrix& mobj);

#endif
